package www.hn.com.shang.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import www.hn.com.shang.bean.Chengshi;
import www.hn.com.shang.bean.Jiashi;
import www.hn.com.shang.bean.JiashiExample;
import www.hn.com.shang.bean.Weizhang;
import www.hn.com.shang.service.JiashiService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hanni
 * 2019/1/20 0020
 * 14:52
 */

@RestController
public class JiashiController {

    @Reference
    private JiashiService jiashiService;

    @RequestMapping("/list")

    public Map list(Integer page,Integer rows,String jname){
        JiashiExample jiashiExample = null;
        if(jname!=null&&!"".equals(jname)){

          jiashiExample = new JiashiExample();
          jiashiExample.createCriteria().andJnameLike("%"+jname+"%");
        }


        return jiashiService.selectObjects(page,rows,jiashiExample);
    }

    @RequestMapping("/listCheng")

    public List listCheng(Integer pid){

        List<Chengshi> cheng = jiashiService.getCheng(pid);
        return cheng;
    }


    @RequestMapping("/add")

    public Map add(Jiashi jiashi){

        Map map = new HashMap();
        try {
            if(jiashi.getJid()==null||"".equals(jiashi.getJid())){
                jiashi.setJtiao(0);
                jiashiService.insert(jiashi);
            }else{

//                jiashi.setSheng(sheng);
//                jiashi.setShi(shi);
//                jiashi.setQu(qu);
              // System.out.println(sheng+"   "+shi );

                jiashiService.update(jiashi);
            }

            map.put("success",true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success",false);
        }

        return map;

    }

    @RequestMapping("/weizhang")

    public List weizhang(Model model,Integer jid){

        List<Weizhang> weizhang = jiashiService.getWeizhang(jid);

        return weizhang;
    }











}
